using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using BW.WMS.WareHouseStatistics.SignalR;
using BW.WMS.Web.Hubs;

namespace BW.WMS.Web.Services
{
    public class StatisticsNotificationHandler :
        ILocalEventHandler<StatisticsNotificationEventData>,
        ITransientDependency
    {
        private readonly IHubContext<DashboardHub> _hubContext;

        public StatisticsNotificationHandler(IHubContext<DashboardHub> hubContext)
        {
            _hubContext = hubContext;
        }

        public async Task HandleEventAsync(StatisticsNotificationEventData eventData)
        {
            await _hubContext.Clients.All.SendAsync("ReceiveMessage", eventData.Message);
        }
    }
}